#ifndef __BACK_UP_INFO__
#define __BACK_UP_INFO__

#include "util.hpp"
#include "config.hpp"

namespace cloud
{
    struct BackupInfo
    {
        std::string _time; // 文件上传时间
        size_t _fsize;
        std::string _filename;
        std::string _packname;
        std::string _pack_path; // 压缩文件存放路径
        std::string _real_path; // 原文件存放路径
        std::string _url;
        std::string _md5;                                // 文件md5值
        void initByRealPath(const std::string &realpath) // 添加新的文件时调用
        {
            FileUtil file(realpath);
            std::string content;
            Config *conf = Config::GetInstance();

            _filename = file.FileName();
            time_t tmp = file.LastMTime();
            _time=timestampToDateStr(tmp);
            _fsize = file.FileSize();
            // ./backdir/a.txt   ->	  /download/a.txt
            _url = conf->GetDownloadPrefix() + file.FileName(); // 下载前缀加文件名组成URL
            _pack_path = conf->GetTmpPath() + _filename + conf->GetPackFileSuffix();
            _packname = _filename + conf->GetPackFileSuffix();
            _real_path = realpath;
            _md5 = file.GetMD5(); // 获取文件md5值
        }

    private:
        std::string timestampToDateStr(time_t timestamp)
        {
            std::time_t t = timestamp;
            struct tm *timeinfo;
            char buffer[80];

            timeinfo = std::localtime(&t);

            std::strftime(buffer, sizeof(buffer), "%Y-%m-%d", timeinfo);

            return std::string(buffer);
        }
    };

} // namespace cloud

#endif //__BACK_UP_INFO__